package com.lsc.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @program: springboot-swagger
 * @description: swagger配置类
 * @author: 上河图
 * @create: 2020-10-19 18:11
 */

@Configuration
@EnableSwagger2  //开启swagger2
public class swaggerConfig{

/*
*  .select()
* .apis(RequestHandlerSelectors.basePackage("com.lsc.Controller"))
  .build();这是一套体系
* */

    @Bean
    public Docket docket(Environment environment){

        //选择要显示swagger的运行环境
        Profiles profiles = Profiles.of("dev");
        boolean acceptsProfiles = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("A组")
                .enable(acceptsProfiles)  //判断是否为true 来是否开启swagger
                .select()
                //RequestHandlerSelectors配置接口方式   basePackage扫描注解下的接口
                .apis(RequestHandlerSelectors.basePackage("com.lsc.Controller"))
                .build();

    }
//    api接口信息
    @Bean
    public ApiInfo apiInfo(){

        Contact contact = new Contact("刘善城",null,"18312575754@163.com");
        return new ApiInfo("寻星科技考核二",  //标题
                "增加项目经验",   //文档描述
                "2.3.4",  //版本号
                "https://gitee.com/lsc_12/dashboard/projects",  //请求更改地址
                contact,       //作者的个人信息
                "Apache 2.3.4",
                null,
                new ArrayList());
    }





    @Bean
    public Docket docket2(Environment environment){

        //选择要显示swagger的运行环境
        Profiles profiles = Profiles.of("dev");
        boolean acceptsProfiles = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("B组")
                .enable(acceptsProfiles)  //判断是否为true 来是否开启swagger
                .select()
                //RequestHandlerSelectors配置接口方式   basePackage扫描注解下的接口
                .apis(RequestHandlerSelectors.basePackage("com.lsc.Controller.helloController"))
                .build();

    }
}
